package com.egreen.system.controller;


import com.egreen.common.Result;


import com.egreen.common.pojo.DTO.system.SystemAnnouncementDTO;

import com.egreen.common.pojo.VO.system.GetSystemAnnouncementVO;
import com.egreen.system.service.ISystemAnnouncementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cloudJiang
 * @since 2022-07-16
 */
@RestController
@RequestMapping("/systemAnnouncement")
@Api(tags = "系统公告")
public class SystemAnnouncementController {
    @Autowired
    ISystemAnnouncementService iSystemAnnouncementService;

    /**
     * 系统公告查看
     *
     * @return
     */
    @GetMapping("/getAll")
    @ApiOperation(value = "系统公告查看", notes = "通过调用getAllSystemAnnouncement方法查看系统公告，不需要任何参数")
    public Result getAllSystemAnnouncement(){
        List<GetSystemAnnouncementVO> allSystemAnnouncement = iSystemAnnouncementService.getAllSystemAnnouncement();
        return Result.OK(allSystemAnnouncement);
    }

    /**
     * 添加系统公告
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加系统公告",notes ="通过调用addSystemAnnouncement方法，添加系统公告")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "公告id（int类型），id可以不用传", required = true),
            @ApiImplicitParam(name = "title", value = "公告标题", required = true),
            @ApiImplicitParam(name = "content", value = "公告内容", required = true),
            @ApiImplicitParam(name = "systemAnnouncementDTO", value = "以上属性被封装到这个DTO里")
    })
    public Result addSystemAnnouncement(@RequestBody SystemAnnouncementDTO systemAnnouncementDTO){
        iSystemAnnouncementService.addSystemAnnouncement(systemAnnouncementDTO);
        return Result.OK();
    }

    /**
     * 删除系统公告
     */
    @GetMapping("/delete/{id}")
    @ApiOperation(value = "删除系统公告",notes ="deleteSystemAnnouncement，删除系统公告")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "公告id", required = true)
    })
    public Result deleteSystemAnnouncement(@PathVariable int id){
        iSystemAnnouncementService.deleteSystemAnnouncement(id);
        return Result.OK();
    }


}

